<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta name="author" content="hexinyang">
	<title>同步卡数据</title>
	<script language="javascript" src="../script/common.js" type="text/javascript"></script>	
	<script language="javascript" src="../script/card.js" type="text/javascript"></script>
	<script type="text/javascript">    
		//页面控件初始化
	var cardUser;
	var cardPin;
	function load(){
		Eui.showNavigation();
		setPages(["readcardview"])	
		Rpc.loadPage("carddiv","contrast_card_div.html");
	}

	//读卡
	function onReadCard(){
		try{
			Rpc.loadPage("carddiv","contrast_card_div.html");
			var data = CardMgnt.onFindCard(readCardForm,"mgntQueryService.getSyncCardInfo",null,true);
			var card = data.card;
			if (card.status != CardStatus.OK) {showWarning("卡片为"+Common.getText(CardStatus.CATEGORY,card.status)+"状态，不能同步卡数据！");return;}
			if (card.storeStatus != CardStoreStatus.IN_USE) {showWarning("卡片库存为"+Common.getText(CardStoreStatus.CATEGORY,card.storeStatus)+"状态，不能同步卡数据！");return;}
			
			cardUser = data.cardUser;
			cardPin = data.cardPin;
			$("syncbtn").disabled = false;
			
			CardMgnt.contrastCard(readCardForm,data.cardInfo)
		}catch(e){
			showError(e.description);
		}
	}
	
	
	function doSyncCard(){
		if (!showQuestion("是否同步卡数据？")) return;
		var asn = readCardForm.asn.value;
		if (!CardMgnt.checkCardAsn(asn)) return;
		
		var usePin = cardUser.usePin;	
		var cPin = getNeedPin();
		
		var getText = function(c){
			return c ? "启用":"停用"
		}
		
		if (usePin != cPin){
			showWarning("卡内密码标志("+getText(cPin)+")与后台密码标志("+getText(usePin)+")不一致，<br>需先"+getText(usePin)+"卡密码！");
			try{
				var res = CardMgnt._usePinApp(asn,usePin,cardPin);
				cardPin = res.pin;
			}catch(e){showError(e.description);return;}
		}
		if (!cardPin) return;
		
		try{
			CardMgnt.syncCardData(asn,cardPin);
		}catch(e){
			showError(e.description);
			return;
		}
		showInformation("同步卡数据成功！");
		onCancel();
	}
	
	function onCancel(){
		cardUser = null;
		Rpc.loadPage("carddiv","contrast_card_div.html");
		$("syncbtn").disabled = true;
	}
	</script>
	</head>
	<body onload="load()">
		<!--页面导航-->
		<div class="nav"><div id="nav">&nbsp;</div></div>
		<div id="readcardview">
			<form name="readCardForm" id="readCardForm">
				<div id="carddiv" class="form">
				</div>
			</form>
			<p>
				<button name="read" id="readCardbtn" onclick="onReadCard()">读 卡</button>
				<button id="syncbtn" onclick="doSyncCard()" disabled>同步卡数据</button>
				<button onclick="onCancel()">重 置</button>
			</p>
		</div>
		<div id="tttt"></div>
	</body>
</html>